/*
 * Edit.java
 *
 * Created on 14 marzec 2007, 22:05
 *
 */

package arocms.gallery;

import arocms.business.Image;
import arocms.business.ImageDAO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author arek
 */
public class Edit extends Action{
    
    private final static String SUCCESS = "success";
    private final static String FAILURE = "failure";
    private Logger log = Logger.getLogger(this.getClass());
    
    /** Creates a new instance of Edit */
    public Edit() {
    }
    
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        try {
            String id = request.getParameter("id");
            Long pk = new Long(id);
            Image img = new ImageDAO().find(pk);
            //ImageForm frm = (ImageForm) form;
            ImageForm frm = new ImageForm();
            frm.setId(img.getId().toString());
            frm.setTitle(img.getTitle());
            frm.setDescription(img.getDescription());
            request.setAttribute(mapping.getAttribute(),frm);
        } catch (Exception ex) {
            return mapping.findForward(FAILURE);
        }
        return mapping.findForward(SUCCESS);
    }
    
}
